<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Album extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('plan');
	}
    
	
	public function lists(){
		$page=$this->input->get('page');

		//列表的第N页，默认第一页
		$pid=intval($page)>1?intval($page):1;

		

		//每页数据条目
		$pageItemCount=20;

		$show_page=7;

		$pageOffset=($show_page-1)/2;
			


		$OUTPUT=array();
		
		/**
		* 校验pid为数字
		*/
		if(!preg_match('/^[1-9]\d*$/',$pid)){
			
			$OUTPUT['code']=3;
			$OUTPUT['status']='Invalid Parameter';
			
			show_404('页面');
			
			exit;
		}

		$this->load->database();

		$offset=($pid-1)*$pageItemCount;
		
		//使用CI内置数据库查询方法，简化查询语句
		$this->db->select('id ,title,desc,poster,author_name AS authorName,author_id AS authorId,create_date AS createDate');
		
		$OUTPUT['data']=$this->db->order_by('id','DESC')->get('slide_item_tb', $pageItemCount,$offset)->result_array();
		
		if(empty($OUTPUT['data'])){
			//show_404('页面');
			//exit;
		}
		
		$OUTPUT['recordCount']=$this->db->count_all('slide_item_tb');



		$OUTPUT['categoryList']=array(
			null,'Industry News','Events','Product Updates','Industry Knowledge','Trends & Insights'
		);


		//总页数
		$OUTPUT['total_pages']=intval(ceil($OUTPUT['recordCount']/$pageItemCount));
		$OUTPUT['page']=$page;
		$OUTPUT['show_page']=$show_page;
		$OUTPUT['pageOffset']=$pageOffset;
		
		

		$this->load->view('slide_list',$OUTPUT);
	}
    
	
	public function preview($pid){
        $this->load->view('slide_item_preview');
    }
	
	
    public function item($pid){
		$OUTPUT=array();
		$OUTPUT['aId']=$pid;
        $this->load->view('slide_item',$OUTPUT);
    }
	
	
	
}
